
var CustomerController = function($scope, $http, $modal){
	$http.defaults.headers.post["Content-Type"] = "application/json";
	var urlBase="http://localhost:8080/project";
	
	$scope.getListCustomer = function(){
		$scope.resetError();
		$http.get(urlBase + '/customer/getList').success(function(respone){
			$scope.listCustomer = respone;
		}).error(function(){
			$scope.setError("Can't get all customer");
		});
	}
	
	$scope.viewAllAccount = function(id){
		$scope.resetError();
		$http.post(urlBase + '/customer/listAccount/' + id).success(function(respone){
			var modalInstance = $modal.open({
			      templateUrl: 'accountCustomer.html',
			      controller: $scope.ModalInstanceCtrlNew,
			      resolve: {
			        items: function () {
			          return respone;
			        }
			      }
			 });
		}).error(function(){
			
		});
	}
	
	$scope.setError = function(message){
		$scope.error = true;
		$scope.errorMessage = message;
	}
	
	$scope.resetError = function(){
		$scope.error = false;
		$scope.errorMessage = '';
	}
	
	$scope.getListCustomer();
	
	
	$scope.ModalInstanceCtrlNew = function ($scope, $modalInstance, items) {
		
		  $scope.listAccountNew = items;
		  
		  $scope.updateAccount = function () {
		    $modalInstance.close();
		  };

		  $scope.cancel = function () {
		    $modalInstance.dismiss('cancel');
		  };
		  
	}
}